package mobile.game.rpc;


import mobile.game.common.config.JConfig;
import mobile.game.common.config.json.JInfo;
import mobile.game.common.net.netty.Client;
import mobile.game.core.Service;
import mobile.game.core.gen.proxy.DistrClass;
import mobile.game.core.gen.proxy.DistrMethod;
import mobile.game.core.scheduler.ScheduleTask;

@DistrClass
public class DefaultService extends Service {
	public DefaultService(String servId) {
		super(servId);
	}

	@Override
	public void onInit() {
		super.onInit();
		
		this.scheduleOnce(new ScheduleTask(this) {
			
			@Override
			public void execute() {
				// TODO Auto-generated method stub
				DefaultService defaultService = getParam().get();
				
				JInfo jInfo = JConfig.getJInfoByServName(defaultService.getId().toString());
				if (null != jInfo) {
					DefaultServiceProxy proxy = DefaultServiceProxy.newInstance(jInfo.getCallPoint());
					proxy.dispatch();
				}
				
				
			}
		}, 3000);
	}

	@DistrMethod
	public void dispatch() {
		System.out.println("call DefaultService.dispatch");
		
		JInfo jInfo = JConfig.getJInfoByServName("testService");
		TestServiceProxy proxy = TestServiceProxy.newInstance(jInfo.getCallPoint());
		proxy.OnTest(48939);
		
		Client client = new Client();
		client.connectServer("127.0.0.1", 12345);
		
		try {
			Thread.sleep(1000);
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		client.disconnect();
	}

}
